import random

# 设定抛硬币的总次数
total_throws = 1000

# 初始化正面和反面的计数
heads_count = 0
tails_count = 0
count = []
# 模拟抛硬币
for _ in range(total_throws):
    result = random.choice(['H', 'T'])
    if heads_count / total_throws == 0.4:
        break
    elif  result == 'H':
            heads_count += 1
    elif result == 'T':
            tails_count += 1

# 计算正面的概率
heads_probability = heads_count / total_throws
# 输出结果
print(f"抛硬币总次数: {heads_count+tails_count}")
print(f"正面向上的次数: {heads_count}")
print(f"反面向上的次数: {tails_count}")
print(f"正面的概率: {heads_probability:.2f}")
print(count)